<template>
    <div>
        <div class="edit_back">
            <Icon type="ios-undo" style="cursor: pointer;" @click="back"></Icon>&nbsp;&nbsp;
            编辑管理员
        </div>
        <div class="edit_form">
            <Form :label-width="100" style="width: 320px;">
                <Form-item label="管理员名称">
                    <Input placeholder="请输入管理员名称" v-model="adminData.name"></Input>
                </Form-item>
                <Form-item label="管理员工号">
                    <Input v-model="adminData.id" disabled></Input>
                </Form-item>
                <Form-item label="管理员手机号">
                    <Input placeholder="请输入管理员手机号" v-model="adminData.phone"></Input>
                </Form-item>
                <Form-item>
                    <Button type="primary" @click="confirm"> 保存</Button>
                    <Button style="margin-left: 8px">取消</Button>
                </Form-item>
            </Form>
        </div>
    </div>
</template>
<script>
import {update} from "@/api/admin/admin";

export default {
    name: 'editAdmin',
    data() {
        return {
            adminData: {
                name: '',
                id: '',
                phone:'',

            }
        }
    },
  mounted() {
    this.adminData.id = this.$route.params.id
  },
  methods: {
        back() {
            this.$router.replace({ name: 'system' })
        },
      confirm(){
          let formData = new FormData()
          formData.append('user_id',this.adminData.id.toString())
          if(this.adminData.name!=='')formData.append('name',this.adminData.name)
          if(this.adminData.phone!=='')formData.append('tel',this.adminData.phone)
          update(formData).then(res => {
              if(res.data.code === 200){
                  this.$Message.success('修改成功')
                  this.$router.replace({ name: 'system' })
              }else{
                  this.$Message.error('修改失败')
              }
          })
      }
    }
}
</script>
<style scoped>
.edit_back {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
}

.edit_form {
    margin-top: 10px;
}
</style>